package com.jdz.noise.controller;


import com.jdz.noise.dao.FlyDao;
import com.jdz.noise.dao.FlyStatusDao;
import com.jdz.noise.entities.FlyRow;
import com.jdz.noise.entities.FlyStatus;
import com.jdz.noise.tools.ControlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@RestController
public class FlyController {
    @Resource
    private FlyDao flyDao;

    @Autowired
    private FlyStatusDao flyStatusDao;

    @GetMapping(value = "/fly/test")
    public String test(){
        return "hello world";
    }
    @GetMapping(value = "/fly/freq")
    public double x(){
        System.out.println("###########################");
        return flyDao.getFreq(1);
    }
    @GetMapping("/save/flyStatus")
    public String saveFlyStatus(){
        if(ControlUtil.list_fly.size()==0)
            return "{\"status\":\"fail\", \"msg\":\"请先上传飞行参数文件!\"}";;
        FlyStatus flyStatus = null;
        flyStatus=ControlUtil.calAverFlyRow();
        //描述
        flyStatus.setDesinfo("测试描述");
        if(flyStatusDao.insertFlyStatus(flyStatus)==1)
            return "{\"id\":\""+flyStatus.getId()+"\"}, \"status\":\"success\"}";
        return "{\"status\":\"fail\"}";
    }

}
